package org.jeeasy.generate.domain;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.dromara.autotable.annotation.mysql.MysqlTypeConstant;
import org.dromara.mpe.autotable.annotation.Column;
import org.dromara.mpe.autotable.annotation.Table;
import org.jeeasy.common.core.annotation.dict.Dict;
import org.jeeasy.common.core.base.BaseEntity;
import org.jeeasy.common.core.enums.BooleanEnum;
import org.jeeasy.generate.emuns.JavaTypeEnum;
import org.jeeasy.generate.emuns.JdbcTypeEnum;

import java.io.Serial;
import java.io.Serializable;

/**
 * 表字段
 *
 * @author mobie
 * @date 2021/11/14
 */
@Data
@EqualsAndHashCode(callSuper = true)
@Accessors(chain = true)
@Table(value = "gen_table_field", comment = "表字段配置")
//@Column(comment = "代码生成表字段信息")
public class GenTableField extends BaseEntity<GenTableField> implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 表ID
     */
    @Column(comment = "表ID", length = 24)
    private String tableId;

    /**
     * 列名
     */
    @Column(comment = "列名", length = 32)
    private String columnName;

    /**
     * 主键
     */
    @Column(comment = "主键", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer primaryKey;

    /**
     * 字段名
     */
    @Column(comment = "字段名", length = 32)
    private String fieldName;

    /**
     * 字段描述
     */
    @Column(comment = "字段描述", length = 64)
    private String description;

    /**
     * 数据类型
     */
    @Column(comment = "数据类型", length = 32)
    @Dict(dictEnum = JdbcTypeEnum.class)
    private String jdbcType;

    /**
     * java类型
     */
    @Column(comment = "java类型", length = 32, defaultValue = "String")
    @Dict(dictEnum = JavaTypeEnum.class)
    private String javaType;

    /**
     * 字段长度
     */
    @Column(comment = "字段长度", length = 8)
    private Integer length;

    /**
     * 小数位
     */
    @Column(comment = "小数位", length = 2)
    private Integer decimalPlaces;

    /**
     * 允许空值
     */
    @Column(comment = "允许空值", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer allowNull;

    /**
     * 默认值
     */
    @Column(comment = "默认值", length = 64)
    private String defaultValue;

    /* 页面配置 */

    /**
     * 字典
     */
    @Column(comment = "字典", length = 32)
    private String dictCode;

    /**
     * 表单类型
     */
    @Column(comment = "表单类型", length = 32)
    private String formType;

    /**
     * 页面配置（json）
     */
    @Column(comment = "页面配置（json）", type = MysqlTypeConstant.TEXT)
    private String viewOptionsJson;

    /**
     * 新增显示
     */
    @Column(comment = "新增显示", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer showAdd;

    /**
     * 修改显示
     */
    @Column(comment = "修改显示", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer showEdit;

    /**
     * 列表展示
     */
    @Column(comment = "列表展示", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer showTable;

    /**
     * 搜索展示
     */
    @Column(comment = "搜索展示", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer showSearch;

    /**
     * 修改时禁用
     */
    @Column(comment = "修改时禁用", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer disableOnEdit;

    /**
     * 新增时禁用
     */
    @Column(comment = "新增时禁用", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer disableOnAdd;

    /**
     * 行内编辑时禁用
     */
    @Column(comment = "行内编辑时禁用", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer disableOnTableEdit;

    /* 校验路径 */
    @Column(comment = "校验路径", length = 64)
    private String fieldPath;

    /**
     * 必填
     */
    @Column(comment = "必填", length = 1, type = MysqlTypeConstant.TINYINT)
    @Dict(dictEnum = BooleanEnum.class)
    private Integer required;

    /**
     * 校验规则
     */
    @Column(comment = "校验规则", length = 128)
    private String rule;

    /* 外键关联 */

    /**
     * 主表
     */
    @Column(comment = "主表", length = 32)
    private String mainTable;

    /**
     * 主表字段
     */
    @Column(comment = "主表字段", length = 32)
    private String mainTableField;

}